package com.wangp.demo.anno.processor;

import sun.misc.Unsafe;

import java.lang.reflect.Field;

/**
 * @author <a href="mailto:wangpeng@i-baby.com" rel="nofollow">wp☠😘✨</a>
 * @version 0.0.1
 * @since 2025/8/16 18:54
 */
public class UnsafeHelper {

    private static Unsafe UNSAFE = null;

    public static Unsafe getUnsafe() {
        if (UNSAFE != null) {
            return UNSAFE;
        }
        try {
            Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
            theUnsafe.setAccessible(true);
            UNSAFE = (Unsafe) theUnsafe.get(null);
        } catch (Exception e) {
            throw ExceptionUtils.wrap(e);
        }
        return UNSAFE;
    }
}
